package com.company.lagou.homework.homework1;

public class Char {

    public static void main(String[] args) {
        String str1 = "ABCD123!@#$%ab";
        System.out.println("字符串有：" + str1);

        // 储存数量
        int n1 = 0;  // 记录大写字母
        int n2 = 0;  // 记录数字
        int n3 = 0;  // 记录小写字母
        int n4 = 0;  // 记录特殊字符

        // 转换数组
        char [] cArr = str1.toCharArray();

        // 记录字符
        StringBuilder sb1 = new StringBuilder();   // 记录大写字母
        StringBuilder sb2 = new StringBuilder();   // 记录数字
        StringBuilder sb3 = new StringBuilder();   // 记录小写字母
        StringBuilder sb4 = new StringBuilder();   // 记录特殊字符

        // 使用for循环识别
        for (int i = 0; i < cArr.length; i++) {
            if ('A' <= cArr[i] && cArr[i] <= 'Z' ) {
                sb1.append(cArr[i]);
                n1++;
            } else if ('0' <= cArr[i] && cArr[i] <= '9' ) {
                sb2.append(cArr[i]);
                n2++;
            } else if ('a' <= cArr[i] && cArr[i] <= 'z'){
                sb3.append(cArr[i]);
                n3++;
            } else {
                sb4.append(cArr[i]);
                n4++;
            }
        }

        // 打印
        System.out.println("大写字母个数有" + n1 + "个，它们有" + sb1);
        System.out.println("数字个数有" + n2 + "个，它们有" + sb2);
        System.out.println("小写字母个数有" + n3 + "个，它们有" + sb3);
        System.out.println("特殊字符个数有" + n4 + "个，它们有" + sb4);

    }
}
